<div class="tmd-doc">
<p></p>
<h1 class="tmd-header-1">
embedding 1
</h1>
<p></p>
<div id="question" class="tmd-base">
<div class="tmd-usual">
What does the following program print?
</div>
<p></p>
<pre class="tmd-code line-numbers">
<code class="language-go">package main

type A struct {
	g int
}

func (A) m() int {
	return 1
}

type B int

func (B) g() {}

func (B) f() {}

type C struct{
	A
	B
}

func (C) m() int {
	return 9
}

func main() {
	var c interface{} = C{}
	_, bf := c.(interface{f()})
	_, bg := c.(interface{g()})
	i := c.(interface{m() int})
	println(bf, bg, i.m())
}
</code></pre>
</div>
<p></p>
<div class="tmd-usual">
Choices:
</div>
<p></p>
<input type="radio" id="choiceA" name="choice" class="choice">
<input type="radio" id="choiceB" name="choice" class="choice">
<input type="radio" id="choiceC" name="choice" class="choice">
<input type="radio" id="choiceD" name="choice" class="choice">
<input type="radio" id="choiceE" name="choice" class="choice">
<input type="radio" id="choiceF" name="choice" class="choice">
<input type="radio" id="choiceG" name="choice" class="choice">
<input type="radio" id="choiceH" name="choice" class="choice">

<div id="choices">

<ul style="list-style-type:none;">
<li><label for="choiceA">false false 9</label></li>
<li><label for="choiceB">false true 9</label></li>
<li><label for="choiceC">true false 9</label></li>
<li><label for="choiceD">true true 9</label></li>
<li><label for="choiceE">false false 1</label></li>
<li><label for="choiceF">false true 1</label></li>
<li><label for="choiceG">true false 1</label></li>
<li><label for="choiceH">true true 1</label></li>
</ul>

</div><p></p>
<div id="answer" class="tmd-base">
<div class="tmd-usual">
Answer: true false 9
</div>
<p></p>
<div class="tmd-usual">
Run it on <a href="https://go.dev/play/p/8afpI_sARYh">Go play</a>.
</div>
<p></p>
<div class="tmd-usual">
Key points:
</div>
<ul class="tmd-list">
<li class="tmd-list-item">
<div class="tmd-usual">
Field <code class="tmd-code-span">C.A.g</code> and method <code class="tmd-code-span">C.B.g</code> collide, so they are both not promoted.
</div>
</li>
<li class="tmd-list-item">
<div class="tmd-usual">
Method <code class="tmd-code-span">C.B.f</code> gets promoted as <code class="tmd-code-span">C.f</code>.
</div>
</li>
<li class="tmd-list-item">
<div class="tmd-usual">
Method <code class="tmd-code-span">C.m</code> overrides <code class="tmd-code-span">C.A.m</code>.
</div>
</li>
</ul>
<p></p>
<div class="tmd-usual">
Please read <a href="https://go101.org/article/type-embedding.html">type embedding</a> for more detailed explanations.
</div>
<p></p>
</div>
<p></p>
</div>
